package com.company.project.service.impl;

import com.company.project.dao.*;
import com.company.project.model.*;
import com.company.project.model.Dictionary;
import com.company.project.service.PeriodicalsService;
import com.company.project.service.ThesisAssessmentResultService;
import com.company.project.service.ThesisAssessmentService;
import com.company.project.service.ThesisService;
import com.company.project.core.AbstractService;
import com.company.project.util.*;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


/**
 * Created by CodeGenerator on 2018/10/08.
 */
@Service
@Transactional
public class ThesisServiceImpl extends AbstractService<Thesis> implements ThesisService {
    @Resource
    private ThesisMapper thesisMapper;

    @Resource
    private PeriodicalsMapper periodicalsMapper;

    @Resource
    private DictionaryMapper dictionaryMapper;

    @Resource
    private PeriodicalsCategoryMapper periodicalsCategoryMapper;

    @Resource
    private PeriodicalsCategoryRMapper periodicalsCategoryRMapper;

    @Resource
    private PeriodicalsDbMapper periodicalsDbMapper;

    @Resource
    private PeriodicalsDbRMapper periodicalsDbRMapper;

    @Resource
    private ThesisAssessmentService ThesisAssessmentService;

    @Resource
    private PeriodicalsService periodicalsService;

    @Value("${titleip}")
    private String titleip;
    @Value("${keywordsip}")
    private String keywordsip;
    @Value("${summaryip}")
    private String summaryip;
    @Value("${TyposIp}")
    private String TyposIp;
    @Value("${SubmitAssessmentIp}")
    private String SubmitAssessmentIp;

    @Resource
    private ThesisAssessmentResultService thesisAssessmentResultService;
    /*private static  Pattern compiles = Pattern.compile("\\[[0-9]+\\]..*");

    private static  Pattern compile = Pattern.compile("\\[[0-9]+\\]..*?\\[[A-Z]{1,}\\]\\.\\d{4}..*");*/

    @Override
    public List selectTh(Integer id) {
        return thesisMapper.selectTh(id);
    }

    /*@Override
    public Map<String,Integer> addThesis(ThesisAndAssessment thesisAndAssessment) {
        Date date = new Date();
        Thesis thesis = thesisAndAssessment.getThesis();
        thesis.setCreateTime(date);
        thesis.setLastModifyTime(date);
        Integer tn =thesisMapper.insertThesis(thesis);
        ThesisAssessment thesisAssessment = new ThesisAssessment();
        if(thesisAndAssessment.getThesisAssessment()!=null){
            thesisAssessment = thesisAndAssessment.getThesisAssessment();
        }
        thesisAssessment.setTid(thesis.getId());
        thesisAssessment.setCreateTime(date);
        thesisAssessment.setLastModifyTime(date);
        Integer thn=ThesisAssessmentService.addThesisAssessmen(thesisAssessment);
        //论文评估
        List<Integer> pList = periodicalsService.getPeriodicalsId();
        List<ThesisAssessmentResult> tList = new ArrayList<>();
        for (int i = 0 ; i<pList.size(); i++){
            ThesisAssessmentResult t = new ThesisAssessmentResult();
            t.setCreateTime(date);
            t.setLastModifyTime(date);
            t.setPid(pList.get(i));
            t.setTaid(thesisAssessment.getId());
            t.setMatchingDegree(100-(i+1)*10);
            if(thesisAssessment.getCategory()!=null &&!("").equals(thesisAssessment.getCategory())){
                t.setReson1("期刊专业为"+thesisAssessment.getCategory());
            }
            if(thesisAssessment.getLevel()!=null && !("").equals(thesisAssessment.getLevel())){
                t.setReson2("期刊级别为"+thesisAssessment.getLevel());
            }
            if(thesisAssessment.getPublicationCycle()!=null && !("").equals(thesisAssessment.getPublicationCycle())) {
                t.setReson3("期刊发刊周期为" + thesisAssessment.getPublicationCycle());
            }
            if(thesisAssessment.getComprehensiveIf()!=null && !("").equals(thesisAssessment.getComprehensiveIf())) {
                t.setReson4("期刊影响因子" + thesisAssessment.getComprehensiveIf());
            }
            t.setReson5("期刊排期时间为2个月");
            t.setReson6(" 期刊通过率为3.5%");

            tList.add(t);
        }
        Integer tr =thesisAssessmentResultService.addThesisAssessmentResult(tList);
        Map<String,Integer> map  = new HashMap<>(10);
        if( tn!=null && thn!=null && tr!=null && tn > 0 && thn > 0 && tr > 0 ){
            map.put("thesisId",thesis.getId());
            map.put("thesisAssessmentId",thesisAssessment.getId());
            return map;
        }

        return map;
    }*/

    @Override
    public Map<String, Integer> addThesis(ThesisAndAssessment thesisAndAssessment) {
        Date date = new Date();
        Thesis thesis = thesisAndAssessment.getThesis();
        thesis.setCreateTime(date);
        thesis.setLastModifyTime(date);
        Integer tn = thesisMapper.insertThesis(thesis);
        ThesisAssessment thesisAssessment = new ThesisAssessment();
        if (thesisAndAssessment.getThesisAssessment() != null) {
            thesisAssessment = thesisAndAssessment.getThesisAssessment();
        }
        thesisAssessment.setTid(thesis.getId());
        thesisAssessment.setCreateTime(date);
        thesisAssessment.setLastModifyTime(date);
        Integer thn = ThesisAssessmentService.addThesisAssessmen(thesisAssessment);
        //论文评估
        String param = "{\"param\":\"" + thesis.getcTitle() + thesis.getcKeys() + "\"}";
        JSONArray assessJson = HttpUtil.httpPosta(SubmitAssessmentIp, param);
        List<List> assessList = (List) JSONArray.toCollection(assessJson);
        List<PeriodicalsAssessModell> pList = this.getAssessPeriodicals(assessList);
        List<ThesisAssessmentResult> tList = new ArrayList<>();
        for (int i = 0; i < pList.size(); i++) {
            Integer score = 0;
            PeriodicalsAssessModell p = pList.get(i);
            ThesisAssessmentResult t = new ThesisAssessmentResult();
            t.setCreateTime(date);
            t.setLastModifyTime(date);
            t.setPid(p.getPeriodicalsId());
            p.setScore(p.getScore() / 10);
            score += p.getScore();
            //专业
            StringBuffer x = new StringBuffer("");
            if (thesisAssessment.getCategory() != null && !("").equals(thesisAssessment.getCategory())) {
                int isEq = 0;
                if (p.getPeriodicalsCategory().size()!=0 && null!=p.getPeriodicalsCategory()){
                    for (String pcr : p.getPeriodicalsCategory()) {
                        x.append(pcr + ",");
                        for (String cy : thesisAssessment.getCategory().split(",")) {
                            if (cy.equals(pcr)) {
                                isEq = 1;
                                break;
                            }
                        }
                    }
                    if (isEq == 1) {
                        score += 1;
                    }
                }
                t.setReson1(x.toString() + isEq);
            } else {
                for (String pcr : p.getPeriodicalsCategory()) {
                    x.append(pcr + ",");
                }
                score += 1;
                t.setReson1(x.toString() + 1);
            }
            //级别
            if (thesisAssessment.getLevel() != null && !("").equals(thesisAssessment.getLevel())) {
                int isEq = 0;
                for (String s : thesisAssessment.getLevel().split(",")) {
                    if (null!=p.getLevel()&& s.equals(p.getLevel())) {
                        isEq = 1;
                        break;
                    }
                }
                if (isEq == 1) {
                    score += 1;
                }
                t.setReson2(p.getLevel() + "," + isEq);
            } else {
                score += 1;
                t.setReson2(p.getLevel() + "," + 1);
            }
            //周期
            if (thesisAssessment.getPublicationCycle() != null && !("").equals(thesisAssessment.getPublicationCycle())) {
                int isEq = 0;
                for (String s : thesisAssessment.getPublicationCycle().split(",")) {
                    if (null!=p.getPublicationCycle() && s.equals(p.getPublicationCycle())) {
                        isEq = 1;
                        break;
                    }
                }
                if (isEq == 1) {
                    score += 1;
                }
                t.setReson3(p.getPublicationCycle() + "," + isEq);
            } else {
                score += 1;
                t.setReson3(p.getPublicationCycle() + "," + 1);
            }
            //影响因子
            if (thesisAssessment.getComprehensiveIf() != null && !("").equals(thesisAssessment.getComprehensiveIf())) {
                int isEq = 0;
                if (null != p.getCombinedIf() && !("").equals(p.getCombinedIf())) {
                    for (int k = 0; k < thesisAssessment.getMin().size(); k++) {
                        if (thesisAssessment.getMin().get(k) < Double.parseDouble(p.getCombinedIf())) {
                            if (thesisAssessment.getMax().size() - 1 >= k) {
                                if (thesisAssessment.getMax().get(k) > Double.parseDouble(p.getCombinedIf())) {
                                    isEq = 1;
                                    break;
                                }
                            } else {
                                isEq = 1;
                                break;
                            }
                        }
                    }
                }
                if (isEq == 1) {
                    score += 1;
                }
                t.setReson4(p.getCombinedIf() + "," + isEq);
            } else {
                score += 1;
                t.setReson4(p.getCombinedIf() + "," + 1);
            }
            //核心
            StringBuffer pdbx = new StringBuffer("");
            if (thesisAssessment.getPeriodicalsDb() != null && !("").equals(thesisAssessment.getPeriodicalsDb())) {
                int isEq = 0;
                if (p.getPeriodicalsDb()!=null && !("").equals(p.getPeriodicalsDb())){
                    for (String pdb : p.getPeriodicalsDb()) {
                        pdbx.append(pdb + ",");
                        for (String cy : thesisAssessment.getPeriodicalsDb().split(",")) {
                            if (cy.equals(pdb)) {
                                isEq = 1;
                                break;
                            }
                        }
                    }
                    if (isEq == 1) {
                        score += 1;
                    }
                }
                t.setReson5(pdbx.toString() + isEq);
            } else {
                if(null!=p.getPeriodicalsDb() && p.getPeriodicalsDb().size()>0){
                    for (String pdb : p.getPeriodicalsDb()) {
                        pdbx.append(pdb + ",");
                    }
                }
                score += 1;
                t.setReson5(pdbx.toString() + 1);
            }
            t.setScore(score);
            t.setMatchingDegree(score);
            t.setTaid(thesisAssessment.getId());
            tList.add(t);
        }
        Collections.sort(tList);
        for (ThesisAssessmentResult v : tList){
            System.out.println(v.getScore());
        }
        Integer tr = null;
        if (tList.size() <= 6) {
            tr = thesisAssessmentResultService.addThesisAssessmentResult(tList);
        } else {
            tr = thesisAssessmentResultService.addThesisAssessmentResult(tList.subList(0, 6));
        }
        Map<String, Integer> map = new HashMap<>(10);
        if (tn != null && thn != null && tr != null && tn > 0 && thn > 0 && tr > 0) {
            map.put("thesisId", thesis.getId());
            map.put("thesisAssessmentId", thesisAssessment.getId());
            return map;
        }
        return map;
    }


    @Override
    public Thesis getThsisById(Integer id) {
        return thesisMapper.selectThesisById(id);
    }


    //后台查询全部稿件
    @Override
    public PageUtil<Thesis> selectAllThesis(Integer pageIndex) {
        PageUtil<Thesis> pageUtil = new PageUtil();
        pageUtil.setPageSize(15);
        pageUtil.setCpage(pageIndex);
        pageUtil.setTotalRow(this.selectAllThesisUnm());
        pageUtil.setLists(thesisMapper.selectAllThesis(pageUtil));
        return pageUtil;
    }

    //查询全部稿件数量
    @Override
    public Integer selectAllThesisUnm() {
        return thesisMapper.selectAllThesisUnm();
    }


    //后台查询待处理稿件
    @Override
    public PageUtil<Thesis> selectPending(Integer pageIndex) {
        PageUtil<Thesis> pageUtil = new PageUtil();
        pageUtil.setPageSize(5);
        pageUtil.setCpage(pageIndex);
        pageUtil.setTotalRow(this.selectPendingNum());
        pageUtil.setLists(thesisMapper.selectPending(pageUtil));
        return pageUtil;
    }


    //后台查询待处理稿件数量
    @Override
    public Integer selectPendingNum() {
        return thesisMapper.selectPendingNum();
    }


    //根据论文id查询论文详情
    @Override
    public Thesis selectParticularsById(Integer id) {
        Thesis thesis = thesisMapper.selectParticularsById(id);
        if (thesis.getAuthors() == null) {
            thesis.setAuthorsNum(0);
        } else {
            thesis.setAuthorsNum(thesis.getAuthors().size());
        }
        return thesisMapper.selectParticularsById(id);
    }


    @Override
    public Integer updateParticularsById(Thesis thesis) {
        return thesisMapper.updateByPrimaryKeySelective(thesis);
    }

    @Override
    public Integer insertSelective(Thesis thesis) {
        return thesisMapper.insertSelective(thesis);
    }

    /**
     * 查询全部稿件管理
     *
     * @param pageIndex
     * @return
     * @author liuhan
     */
    @Override
    public PageUtil<Thesis> selectManuscriptManagement(Integer pageIndex) {
        PageUtil<Thesis> pageUtil = new PageUtil();
        pageUtil.setPageSize(10);
        pageUtil.setCpage(pageIndex);
        pageUtil.setTotalRow(this.selectManuscriptManagementNum());
        pageUtil.setLists(thesisMapper.selectManuscriptManagement(pageUtil));
        return pageUtil;
    }

    /**
     * 查询稿件管理数量
     *
     * @return
     * @author liuhan
     */
    @Override
    public Integer selectManuscriptManagementNum() {
        return thesisMapper.selectManuscriptManagementNum();
    }

    /**
     * 前台搜索框搜索论文
     *
     * @param cname
     * @param index
     * @return
     * @author liuhan
     */
    @Override
    public PageUtil<Map<Object, Object>> queryThesis(String cname, Integer index) {
        PageUtil<Map<Object, Object>> pageUtil = new PageUtil();
        pageUtil.setPageSize(15);
        pageUtil.setCpage(index);
        pageUtil.setTotalRow(this.queryThesisCount(cname));
        List<Map<Object, Object>> maps = thesisMapper.queryThesis(pageUtil, cname);
        for (int i = 0; i < maps.size(); i++) {
            maps.get(i).put("value", "论文");
        }
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        for (Map<Object, Object> map : maps) {
            map.put("deliveryTime", format.format(map.get("deliveryTime")));
        }
        pageUtil.setLists(maps);
        return pageUtil;
    }

    /**
     * 前台搜索框搜索论文的数量
     *
     * @param cname
     * @return
     * @author liuhan
     */
    @Override
    public Integer queryThesisCount(String cname) {
        return thesisMapper.queryThesisCount(cname);
    }

    /**
     * 文件格式检验
     * @author liuhan
     * @param txt
     * @return
     */
   /* @Override
    public List DocumentFormatCheck(String txt) {
        List list= new ArrayList(10);
        List list1 = new ArrayList(10);
        Boolean falg = true;
        //根据正则找到符合基本条件的参考文献数据
        String[] split = txt.split("\n");

        Pattern all = Pattern.compile("\\[[0-9]+\\](([\\u4e00-\\u9fa5]+|[a-z-A-Z\\s]+)\\,)+([\\u4e00-\\u9fa5]+|[a-z-A-Z\\s]+)\\.$");
        Pattern all1 = Pattern.compile("^\\S.+(\\[[A-Z]\\]\\.)");
        Pattern all2 = Pattern.compile("((([\\u4e00-\\u9fa5]|[a-z-A-Z\\s])+\\,){0,}(([\\u4e00-\\u9fa5]|[a-z-A-Z\\s])+\\:([\\u4e00-\\u9fa5]|[a-z-A-Z\\s])+\\,){0,}(\\d{0,}){0,}\\[\\d{0,}\\-\\d{2}\\-\\d{2}\\]\\.)|((\\d{4}\\-\\d{2}\\-\\d{2}){0,}(\\[(\\d{4}\\-\\d{2}\\-\\d{2})\\]){0,}\\.)" +
                "|((([\\u4e00-\\u9fa5]+\\:[\\u4e00-\\u9fa5]+\\,)|([\\u4e00-\\u9fa5]+\\,))|(([a-zA-Z\\s]+\\:[a-zA-Z\\s]+\\,)|([a-zA-Z\\s]+\\,))(\\d{4}\\,\\d{0,}\\(\\d{0,}\\)(\\:|\\,)\\d{0,}\\-\\d{0,}(\\[\\d{4}\\-\\d{2}\\-\\d{2}\\]){0,}\\.))" +
                "|(((\\d{4}\\,\\d{0,}\\(\\d{0,}\\)\\-\\.)|(\\d{4}\\(\\d{0,}\\)\\-\\d{4}\\(\\d{0,}\\)\\.))(([\\u4e00-\\u9fa5a-zA-Z\\s]+\\:[\\u4e00-\\u9fa5a-zA-Z\\s]+)\\,|([\\u4e00-\\u9fa5a-zA-Z\\s]+)\\,)\\d{4}\\-((\\d{4}){0,})\\.)" +
                "|((([\\u4e00-\\u9fa5]+|[a-z-A-Z\\s]+)(，|\\,)?)+\\.)?∥(([\\u4e00-\\u9fa5]+|[a-z-A-Z\\s]+)(，|\\,)?)+\\.(([\\u4e00-\\u9fa5-0-9]+|[a-zA-Z-0-9\\s]+)(：|:))?(([\\u4e00-\\u9fa5-0-9]+|[a-zA-Z-0-9\\s]+)\\.)(([\\u4e00-\\u9fa5,，]+|[a-zA-Z\\s,，]+)\\.)?([\\u4e00-\\u9fa5]+|[a-zA-Z\\s]+)(：|:)" +
                "|((([\\u4e00-\\u9fa5]+|[a-z-A-Z\\s]+)(，|\\,)?)+\\.)?∥(([\\u4e00-\\u9fa5]+|[a-z-A-Z\\s]+)(，|\\,)?)+\\.(([\\u4e00-\\u9fa5-0-9]+|[a-zA-Z-0-9\\s]+)(：|:))?(([\\u4e00-\\u9fa5-0-9]+|[a-zA-Z-0-9\\s]+)\\.)(([\\u4e00-\\u9fa5,，]+|[a-zA-Z\\s,，]+)\\.){0,2}([\\u4e00-\\u9fa5]+|[a-zA-Z\\s]+)(：|:)([\\u4e00-\\u9fa5]+|[a-zA-Z\\s]+)(\\,|\\，)([0-9]+[:：])?[0-9]+(-)?([0-9]+)?(\\.)?(\\[([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|[0-9]{1}[1-9][0-9]{2}|[1-9][0-9]{3})-(((0[13578]|1[02])-(0[1-9]|[12][0-9]|3[01]))|((0[469]|11)-(0[1-9]|[12][0-9]|30))|(02-(0[1-9]|[1][0-9]|2[0-8])))\\]\\.)?([a-zA-z]+://[^\\s]*\\.)?");
        for (String s1:split){
            Map<String,Object> map = new HashMap<>(10);
            if (s1.contains("http:")){
                s1.indexOf("")
            }
            String[] split1 = s1.split("\\.");
            String mess = split1[2];
            if(mess.contains("∥")){ //属于文献

            }else if(){

            }

        }
        return list;
    }
*/


    /**
     * 文件格式检验
     *
     * @param txt
     * @return
     * @author liuhan
     */
    @Override
    public List DocumentFormatCheck(String txt) {
        List<Map> resList = new ArrayList<>();
        Pattern all = Pattern.compile("([\\u4e00-\\u9fa5，\\,]+|[a-z-A-Z\\s，\\,]+)\\.$"); //主要责任者
        Pattern all1 = Pattern.compile("^\\S.+(\\[[A-Z]\\]\\.)");  // 题名
        Pattern reZhuanzhuTyp1 = Pattern.compile("([\\u4e00-\\u9fa5，\\,]+\\.)?([\\u4e00-\\u9fa5-0-9，\\,]+\\.)?[\\u4e00-\\u9fa5]+：[\\u4e00-\\u9fa5]+(\\,|，)((\\d{4}：\\d+(-)?(\\d+)?)|(\\d{4}))(\\[([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|[0-9]{1}[1-9][0-9]{2}|[1-9][0-9]{3})-(((0[13578]|1[02])-(0[1-9]|[12][0-9]|3[01]))|((0[469]|11)-(0[1-9]|[12][0-9]|30))|(02-(0[1-9]|[1][0-9]|2[0-8])))\\])?\\.");
        Pattern reZhuanzhuType2 = Pattern.compile("((([\\u4e00-\\u9fa5]+|[a-z-A-Z\\s]+)(，|\\,)?)+\\.)?∥(([\\u4e00-\\u9fa5]+|[a-z-A-Z\\s]+)(，|\\,)?)+\\.(([\\u4e00-\\u9fa5-0-9]+|[a-zA-Z-0-9\\s]+)(：|:))?(([\\u4e00-\\u9fa5-0-9]+|[a-zA-Z-0-9\\s]+)\\.)(([\\u4e00-\\u9fa5,，]+|[a-zA-Z\\s,，]+)\\.){0,2}([\\u4e00-\\u9fa5]+|[a-zA-Z\\s]+)(：|:)([\\u4e00-\\u9fa5]+|[a-zA-Z\\s]+)(\\,|\\，)([0-9]+[:：])?[0-9]+(-)?([0-9]+)?(\\.)?(\\[([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|[0-9]{1}[1-9][0-9]{2}|[1-9][0-9]{3})-(((0[13578]|1[02])-(0[1-9]|[12][0-9]|3[01]))|((0[469]|11)-(0[1-9]|[12][0-9]|30))|(02-(0[1-9]|[1][0-9]|2[0-8])))\\]\\.)?([a-zA-z]+://[^\\s]*\\.)?");
        Pattern reZhuanzhuType3 = Pattern.compile("\\d{4}(\\,|\\，)\\d{0,}\\(\\d{0,}\\)-(\\d{4}\\(\\d{0,}\\))?\\.[\\u4e00-\\u9fa5\\s]+(\\：|\\:)[\\u4e00-\\u9fa5\\s]+(\\，|\\，)\\d{4}-(\\d{4})?\\.");
        Pattern reZhuanzhuType4 = Pattern.compile("(([\\u4e00-\\u9fa5]+(\\:|\\：)[\\u4e00-\\u9fa5]+(\\,|\\，))|([\\u4e00-\\u9fa5]+(\\,|\\，)))\\d{4}(\\,|\\，)\\d{0,}\\(\\d{0,}\\)(\\:|\\：)\\d{0,}-\\d{0,}(\\[([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|[0-9]{1}[1-9][0-9]{2}|[1-9][0-9]{3})-(((0[13578]|1[02])-(0[1-9]|[12][0-9]|3[01]))|((0[469]|11)-(0[1-9]|[12][0-9]|30))|(02-(0[1-9]|[1][0-9]|2[0-8])))\\])?\\.");
        Pattern reZhuanzhuType5 = Pattern.compile("(\\d{4}\\-\\d{2}\\-\\d{2}){0,}(\\[(\\d{4}\\-\\d{2}\\-\\d{2})\\]){0,}\\.");
        Pattern reZhuanzhuType6 = Pattern.compile("(([\\u4e00-\\u9fa5]+(\\:|\\：))[\\u4e00-\\u9fa5]+(\\,|\\，))?(\\d{4})?\\[\\d{4}-\\d{2}-\\d{2}\\]\\.");
        String[] docsTxtList = txt.split("\n");
        String docs = null; //去过http的单个文献
        String http = null; //http
        for (String docsTxt : docsTxtList) {
            Map<String, Object> res = new HashMap<>();
            if (docsTxt.contains("http")) {
                docs = docsTxt.substring(0, docsTxt.indexOf("http"));
                http = docsTxt.substring(docsTxt.indexOf("http"), docsTxt.length());
            } else {
                docs = docsTxt;
            }
            String[] split = docs.split("\\.");
            if (split.length >= 3) {
                String docsType1 = split[0] + ".";
                String docsType2 = split[1] + ".";
                Boolean state1 = false;
                Boolean state2 = false;
                Boolean state3 = false;
                String errorMessage = "";
                StringBuffer docsTypeSb = new StringBuffer();
                String docsType3 = null;
                for (int i = 2; i < split.length; i++) {
                    docsTypeSb.append(split[i] + ".");
                }
                List<String> errorList = new ArrayList<>();
                if (docsTypeSb.toString() != null) {
                    docsType3 = docsTypeSb.toString();
                    Matcher maZhuanzhu1 = reZhuanzhuTyp1.matcher(docsType3);
                    Matcher maZhuanzhu2 = reZhuanzhuType2.matcher(docsType3);
                    Matcher maZhuanzhu3 = reZhuanzhuType3.matcher(docsType3);
                    Matcher maZhuanzhu4 = reZhuanzhuType4.matcher(docsType3);
                    Matcher maZhuanzhu5 = reZhuanzhuType5.matcher(docsType3);
                    Matcher maZhuanzhu6 = reZhuanzhuType6.matcher(docsType3);
                    if (!all.matcher(docsType1).find()) {
                        errorList.add(docsType1);
                    } else {
                        state1 = true;
                    }
                    if (!all1.matcher(docsType2).find()) {
                        errorList.add(docsType2);
                    } else {
                        state2 = true;
                    }
                    if (docsTxt.contains("∥")) {
                        if (maZhuanzhu2.find()) {
                            state3 = true;
                            errorMessage = "";
                        } else {
                            state3 = false;
                            errorList.add(docsType3);
                            errorMessage = "格式错误！";
                        }
                    } else if (maZhuanzhu1.find()) {
                        state3 = true;
                        errorMessage = "";
                    } else if (maZhuanzhu3.find()) {
                        state3 = true;
                        errorMessage = "";
                    } else if (maZhuanzhu4.find()) {
                        state3 = true;
                        errorMessage = "";
                    } else if (maZhuanzhu5.find()) {
                        state3 = true;
                        errorMessage = "";
                    } else if (maZhuanzhu6.find()) {
                        state3 = true;
                        errorMessage = "";
                    } else {
                        state3 = false;
                        errorList.add(docsType3);
                        errorMessage = "格式错误！";
                    }
                }
                String state = "false";
                if (state1 && state2 && state3) {
                    state = "true";
                }
                res.put("state", state);
                res.put("text", docsTxt);
                res.put("error", errorList);
                res.put("errorMessage", errorMessage);

            } else {
                res.put("state", "false");
                res.put("text", docsTxt);
                res.put("error", new ArrayList<String>().add(docsTxt));
                res.put("errorMessage", "至少三部分信息，以\".\"分割");
            }
            resList.add(res);
        }
        return resList;
    }


    /**
     * 错别字校验
     *
     * @return
     */
    @Override
    public List ProofreadForTypos(String map) {
        JSONArray s = HttpUtil.httpPosta(TyposIp, map);
        List<String> list = new ArrayList<>();
        list.addAll(s);
        return list;
    }

    /**
     * 创新指数校验
     *
     * @return
     * @author liuhan
     */
    @Override
    public List<Object> ManuscriptInnovationIndex(Map<String, String> data) throws UnsupportedEncodingException {
        String s = data.get("title");
        String s1 = data.get("keywords");
        s1 = s1.trim();
        List<String> sp = new ArrayList<>();
        if(s1.contains(";")) {
            sp= Arrays.asList(s1.split(";"));
        }else if(s1.contains("；")) {
            sp= Arrays.asList(s1.split("；"));
        }else {
            sp= Arrays.asList(s1.split(" "));
        }
        StringBuilder builder2 = new StringBuilder();
        for(String str :sp) {
            builder2.append(str.replaceAll(" ", "")).append("||");
        }
        String s3 = builder2.toString().substring(0,builder2.toString().length()-2);
        String s2 = data.get("summary");
        String title = HttpUtil.httpGet(titleip + "text=" + URLEncoder.encode(s, "UTF-8"));
        String keywords = HttpUtil.httpGet(keywordsip + "text=" + URLEncoder.encode(s3, "UTF-8"));
        String summary = HttpUtil.httpGet(summaryip + "text=" + URLEncoder.encode(s2, "UTF-8"));
        JSONObject titleJson = JSONObject.fromObject(title);
        JSONObject keywordsJson = JSONObject.fromObject(keywords);
        JSONObject summaryJson = JSONObject.fromObject(summary);
        int titleResult = titleJson.getInt("result");
        int keywordsResult = keywordsJson.getInt("result");
        int summaryResult = summaryJson.getInt("result");
        int synthesize = (titleResult + keywordsResult + summaryResult) * 3;
        List<Object> list = new ArrayList<>();
        list.add(HttpUtil.unicodeToString(title).replaceAll("\\\\", ""));
        list.add(HttpUtil.unicodeToString(keywords).replaceAll("\\\\", ""));
        list.add(HttpUtil.unicodeToString(summary).replaceAll("\\\\", ""));
        list.add(synthesize);
        return list;
    }


    //期刊评估处理期刊
    private List<PeriodicalsAssessModell> getAssessPeriodicals(List<List> assessList) {
        List<PeriodicalsAssessModell> resultList = new ArrayList<>();
        Map<String,Integer> assessListMap = new HashMap<>();
        Map<Integer, String> dictionariesMap = new HashMap<>();
        Map<Integer, String> periodicalsCategoriesMap = new HashMap<>();
        Map<Integer, List<String>> periodicalsCategoryRSMap = new HashMap<>();
        Map<Integer, String> periodicalsDbsMap = new HashMap<>();
        Map<Integer, List<String>> periodicalsDbRSMap = new HashMap<>();
        //查询数据库
        List<Dictionary> dictionaries = dictionaryMapper.selectDictionaryAssess();
        List<PeriodicalsCategory> periodicalsCategories = periodicalsCategoryMapper.selectPeriodicalsCategoryAssess();
        List<PeriodicalsCategoryR> periodicalsCategoryRS = periodicalsCategoryRMapper.selectPeriodicalsCategoryRAssess();
        List<PeriodicalsDb> periodicalsDbs = periodicalsDbMapper.selectPeriodicalsDbAssess();
        List<PeriodicalsDbR> periodicalsDbRS = periodicalsDbRMapper.selectPeriodicalsDbRAssess();
        List<PeriodicalsAssessModell> periodicalsAssessModellList = periodicalsMapper.selectPeriodicalsAssess();
        //数据处理
        for (List assess : assessList) {
            int score = Integer.parseInt(assess.get(1).toString());
            if (score > 0 && !("").equals(assess.get(0).toString())) {
                assessListMap.put(assess.get(0).toString(),score);
            }
        }
        for (Dictionary dictionarie : dictionaries) {
            dictionariesMap.put(dictionarie.getId(), dictionarie.getValue());
        }
        for (PeriodicalsCategory periodicalsCategory : periodicalsCategories) {
            periodicalsCategoriesMap.put(periodicalsCategory.getId(), periodicalsCategory.getName());
        }
        for (PeriodicalsCategoryR periodicalsCategoryR : periodicalsCategoryRS) {
            if (periodicalsCategoryRSMap.get(periodicalsCategoryR.getPid()) == null) {
                List<String> c = new ArrayList<>();
                c.add(periodicalsCategoriesMap.get(periodicalsCategoryR.getCid()));
                periodicalsCategoryRSMap.put(periodicalsCategoryR.getPid(), c);
            } else {
                List<String> c = periodicalsCategoryRSMap.get(periodicalsCategoryR.getPid());
                c.add(periodicalsCategoriesMap.get(periodicalsCategoryR.getCid()));
                periodicalsCategoryRSMap.put(periodicalsCategoryR.getPid(), c);
            }
        }
        for (PeriodicalsDb PeriodicalsDb : periodicalsDbs) {
            periodicalsDbsMap.put(PeriodicalsDb.getId(), PeriodicalsDb.getName());
        }
        for (PeriodicalsDbR periodicalsDbR : periodicalsDbRS) {
            if (periodicalsDbRSMap.get(periodicalsDbR.getPid()) == null) {
                List<String> c = new ArrayList<>();
                c.add(periodicalsDbsMap.get(periodicalsDbR.getDbid()));
                periodicalsDbRSMap.put(periodicalsDbR.getPid(), c);
            } else {
                List<String> c = periodicalsDbRSMap.get(periodicalsDbR.getPid());
                c.add(periodicalsDbsMap.get(periodicalsDbR.getDbid()));
                periodicalsDbRSMap.put(periodicalsDbR.getPid(), c);
            }
        }
        for (PeriodicalsAssessModell resultPModel : periodicalsAssessModellList) {
            resultPModel.setScore(assessListMap.get(resultPModel.getCname()));
            if(null!=resultPModel.getLevel() && !("").equals(resultPModel.getLevel())){
                resultPModel.setLevel(dictionariesMap.get(Integer.parseInt(resultPModel.getLevel())));
            }else{
                resultPModel.setLevel(null);
            }
            if(null!=resultPModel.getPublicationCycle() && !("").equals(resultPModel.getPublicationCycle())){
                resultPModel.setPublicationCycle(dictionariesMap.get(Integer.parseInt(resultPModel.getPublicationCycle())));
            }else{
                resultPModel.setPublicationCycle(null);
            }
            resultPModel.setPeriodicalsCategory(periodicalsCategoryRSMap.get(resultPModel.getPeriodicalsId()));
            resultPModel.setPeriodicalsDb(periodicalsDbRSMap.get(resultPModel.getPeriodicalsId()));
            if(null!=resultPModel.getScore() && !("").equals(resultPModel.getScore()) && resultPModel.getScore()!=0){
                resultList.add(resultPModel);
            }
        }

        return resultList;
    }

}
